<?php

use common\helpers\ImageHelper;
use common\helpers\Url;
use yii\grid\GridView;
use common\helpers\Html;
use addons\AppVersions\common\enums\TypeEnum;

$this->title = TypeEnum::getValue($type);
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="row">
    <div class="col-xs-12">
        <div class="box">
            <div class="box-header">
                <h3 class="box-title"><?= $this->title; ?></h3>
                <div class="box-tools">
                    <?= Html::create(['edit', 'type' => $type])?>
                </div>
            </div>
            <!-- /.box-header -->
            <div class="box-body table-responsive">
                <?= GridView::widget([
                    'dataProvider' => $dataProvider,
                    'filterModel' => $searchModel,
                    //重新定义分页样式
                    'tableOptions' => [
                        'class' => 'table table-hover rf-table',
                        'fixedNumber' => 1,
                        'fixedRightNumber' => 1,
                    ],
                    'columns' => [
                        [
                            'class' => 'yii\grid\SerialColumn',
                            'visible' => false, // 不显示#
                        ],
                        'id',
                        [
                            'label'=> '二维码',
                            'filter' => false, //不显示搜索框
                            'format' => 'raw',
                            'value' => function($model) {
                                if ($model->type == TypeEnum::ANDROID) {
                                    return ImageHelper::fancyBox(Url::to(['qr', 'url' => $model->download_url]));
                                }

                                return ImageHelper::fancyBox(Url::to(['qr', 'url' => 'https://apps.apple.com/cn/app/id' . $model->download_url]));
                            },
                        ],
                        'title',
                        [
                            'label' => '分类',
                            'attribute' => 'cate.title',
                            'format' => 'raw',
                            'filter' => Html::activeDropDownList($searchModel, 'cate_name', $cateMap, [
                                    'prompt' => '全部',
                                    'class' => 'form-control',
                                ]
                            ),
                        ],
                        [
                            'attribute' => 'version',
                            'headerOptions' => ['class' => 'col-md-1'],
                        ],
                        'version_id',
                        [
                            'attribute' => 'package_size',
                            'headerOptions' => ['class' => 'col-md-1'],
                        ],
                        [
                            'attribute' => 'download_num',
                            'headerOptions' => ['class' => 'col-md-1'],
                        ],
                        [
                            'attribute' => 'is_enforce',
                            'filter' => false, //不显示搜索框
                            'format' => 'raw',
                            'value' => function($model) {
                                return Html::whether($model->is_enforce);
                            },
                        ],
                        [
                            'label'=> '创建日期',
                            'attribute' => 'created_at',
                            'filter' => false, //不显示搜索框
                            'format' => ['date', 'php:Y-m-d H:i:s'],
                        ],
                        [
                            'header' => "操作",
                            'class' => 'yii\grid\ActionColumn',
                            'template'=> '{edit} {status} {delete}',
                            'buttons' => [
                                'edit' => function ($url, $model, $key) {
                                    return Html::edit(['edit', 'id' => $model->id, 'type' => $model->type]);
                                },
                                'status' => function ($url, $model, $key) {
                                    return Html::status($model->status);
                                },
                                'delete' => function ($url, $model, $key) {
                                    return Html::delete(['destroy', 'id' => $model->id]);
                                },
                            ],
                        ],
                    ],
                ]); ?>
                <!-- /.box-body -->
            </div>
            <!-- /.box -->
        </div>
    </div>
</div>